home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2788 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.0 KB

  1. Path: engnews2.Eng.Sun.COM!usenet
  2. From: nitin@more.eng.sun.com (Nitin More [CONTRACTOR])
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help- pointers to functions
  5. Date: 19 Jan 1996 18:05:26 GMT
  6. Organization: SunSoft
  7. Distribution: world
  8. Message-ID: <NITIN.96Jan19100526@more.eng.sun.com>
  9. References: <4djcn5$hfe@matrix.mdn.com>
  10. NNTP-Posting-Host: more.eng.sun.com
  11. In-reply-to: G. Ball's message of 17 Jan 1996 17:47:17 GMT
  12.  
  13. In article <4djcn5$hfe@matrix.mdn.com> G. Ball <gball@aggie.mdn.com> writes:
  14.  
  15.  
  16. You could get the answer to this in any decent C++ book.  Look for "pointer to
  17. function" section.  To make your life easier, you could use typedef and then
  18. use the new type as any other type.  So you could easily define array of this
  19. new type.  For example,
  20.  
  21. typedef int (*FunctionType)(const char *str);
  22.  
  23. Here you have defined a new type called FunctionType which is a pointer to a
  24. function which takes const char* as an argument and returns an int.  Now you
  25. can define the array as follows:
  26.  
  27. FunctionType *functionArray[100];
  28.  
  29. functionArray[0] = &Cut;
  30. functionArray[1] = &Paste;
  31.  
  32. -Nitin
  33.  
  34.  
  35. > From: G. Ball <gball@aggie.mdn.com>
  36. > Newsgroups: comp.lang.c++
  37. > Date: 17 Jan 1996 17:47:17 GMT
  38. > Organization: G. Ball
  39. > X-XXDate: Wed, 17 Jan 1996 13:04:01 GMT
  40. > I need your help!
  41. > I am putting together a set of subroutines that I hope to place in
  42. > several models.
  43. > The problem is I have an unspecified number of function, each requiring
  44. > the same input
  45. > and I would like to refer to them using an array (ie.
  46. > (*function[i])(variable) or something).
  47. > Is it possible or do you have any ideas on alternate solutions?
  48. > Thank you for your time and efforts.
  49. > John 
  50. > jschell@aggie.mdn.com
  51. -- 
  52. ----------------------------------------------------------------------
  53. Nitin More                                                         
  54. SunSoft, Bldg 16  Off: (415) 786 7109                                 
  55. Menlo Park, CA    Fax: (415) 786 7957   e-mail: nitin@more.eng.sun.com
  56. ----------------------------------------------------------------------
  57.